package com.jz.community.moduleshopping.cardGoods.adapter;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.cardGoods.info.CardBrandInfo;

import java.util.List;

/**
 * Created by Tony.Fan on 2018/8/16 11:01
 */
public class CardBrandCategoryAdapter extends BaseQuickAdapter<CardBrandInfo.EmbeddedBeanXXX.ContentBeanXX.EmbeddedBeanXX.ContentBeanX, BaseViewHolder> {

    public CardBrandCategoryAdapter(@Nullable List<CardBrandInfo.EmbeddedBeanXXX.ContentBeanXX.EmbeddedBeanXX.ContentBeanX> data) {
        super(R.layout.module_shopping_card_brand_goods_item_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CardBrandInfo.EmbeddedBeanXXX.ContentBeanXX.EmbeddedBeanXX.ContentBeanX item) {
        BaseImageLoaderUtils.getInstance().loadRamdomImage(mContext, helper.getView(R.id.item_card_much_img), item.getIcon());
        helper.setText(R.id.item_card_much_name, item.getTitle());
        TextView item_card_much_price_red = helper.getView(R.id.item_card_much_price_red);
        TextView item_card_much_price_gray = helper.getView(R.id.item_card_much_price_gray);
        TextView item_card_much_no = helper.getView(R.id.item_card_much_no);

        if (item.getStock() != 0) {
            SHelper.gone(item_card_much_no);
        } else {
            SHelper.vis(item_card_much_no);
        }

        if (!Preconditions.isNullOrEmpty(item.getSkuInfos())) {
            if (!Preconditions.isNullOrEmpty(item.getSkuInfos().get(0).getDiscountPrice())) {
                item_card_much_price_red.setText(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getSkuInfos().get(0).getDiscountPrice())));
                SHelper.vis(item_card_much_price_gray);
                RxTextTool.getBuilder("").append(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getSkuInfos().get(0).getPrice()))).setStrikethrough().into(item_card_much_price_gray);
            } else {
                SHelper.gone(item_card_much_price_gray);
                item_card_much_price_red.setText(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getSkuInfos().get(0).getPrice())));
            }
        }

    }

}
